package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.Trusteddevice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITrusteddeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 可信设备Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/trusteddevice")
public class TrusteddeviceController extends BaseController
{
    @Autowired
    private ITrusteddeviceService trusteddeviceService;

    /**
     * 查询可信设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Trusteddevice trusteddevice)
    {
        startPage();
        List<Trusteddevice> list = trusteddeviceService.selectTrusteddeviceList(trusteddevice);
        return getDataTable(list);
    }

    /**
     * 导出可信设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:export')")
    @Log(title = "可信设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Trusteddevice trusteddevice)
    {
        List<Trusteddevice> list = trusteddeviceService.selectTrusteddeviceList(trusteddevice);
        ExcelUtil<Trusteddevice> util = new ExcelUtil<Trusteddevice>(Trusteddevice.class);
        return util.exportExcel(list, "可信设备数据");
    }

    /**
     * 获取可信设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:query')")
    @GetMapping(value = "/{tdid}")
    public AjaxResult getInfo(@PathVariable("tdid") String tdid)
    {
        return AjaxResult.success(trusteddeviceService.selectTrusteddeviceByTdid(tdid));
    }

    /**
     * 新增可信设备
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:add')")
    @Log(title = "可信设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Trusteddevice trusteddevice)
    {
        return toAjax(trusteddeviceService.insertTrusteddevice(trusteddevice));
    }

    /**
     * 修改可信设备
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:edit')")
    @Log(title = "可信设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Trusteddevice trusteddevice)
    {
        return toAjax(trusteddeviceService.updateTrusteddevice(trusteddevice));
    }

    /**
     * 删除可信设备
     */
    @PreAuthorize("@ss.hasPermi('system:trusteddevice:remove')")
    @Log(title = "可信设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tdids}")
    public AjaxResult remove(@PathVariable String[] tdids)
    {
        return toAjax(trusteddeviceService.deleteTrusteddeviceByTdids(tdids));
    }
}
